﻿#ifndef HNRJITDIALOG_H
#define HNRJITDIALOG_H

#include "HnrjitWigdet.h"

class CHnrjitContainer;

class DIRECTUI_API CHnrjitDialog : public CHnrjitWigdet
{
public:
	explicit CHnrjitDialog();
	virtual ~CHnrjitDialog();

	/// <summary>获取当前类标识</summary>
	virtual DWORD GetClsid() const { return CLSID_HNRJITDIALOG; }

	/// <summary>设置属性值</summary>
	/// <param name="pxElement">XML元素</param>
	virtual void SetAttribute(const TiXmlElement* pxElement, HZIP hZipRes = NULL);

public:
	virtual void SetLocation(const CPoint& ptLocation);
	virtual void SetLocation(int nX, int nY);

	virtual void SetSize(const CSize& tagSize);
	virtual void SetSize(int nWidth, int nHeight);

	virtual void SetGeometry(CPoint ptLocation, CSize tagSize);
	virtual void SetGeometry(int nX, int nY, int nWidth, int nHeight);

	virtual BOOL IsEnabled() const;
	virtual void SetEnabled(BOOL isEnabled);

	virtual BOOL IsVisible() const;
	virtual void SetVisible(BOOL isVisible);

	/// <summary>绘制窗口</summary>
	/// <param name="rcRect">要绘制区域</param>
	virtual void Invalidate(const CRect& rcRect);

public:
	/// <summary>对话框标题属性</summary>
	virtual const CAtlString& GetCaption() const;
	virtual void SetCaption(const TCHAR* pszCaption);

	/// <summary>插入次序属性</summary>
	HWND GetInsertAfter() const;
	void SetInsertAfter(HWND hWndInsertAfter);

protected:
	/// <summary>自绘窗口</summary>
	/// <param name="rcClipBox">裁剪区域</param>
	/// <param name="pDC">设备上下文</param>
	virtual void DrawDailog(HDC hdc);

	/// <summary>键盘按下事件</summary>
	/// <param name="nChar">虚拟键码</param>
	/// <param name="nRepCnt">重复次数</param>
	/// <param name="nFlags">扫描代码</param>
	virtual void OnKeyPress(UINT nChar, UINT nRepCnt, UINT nFlags);

	/// <summary>键盘释放事件</summary>
	/// <param name="nChar">虚拟键码</param>
	/// <param name="nRepCnt">重复次数</param>
	/// <param name="nFlags">扫描代码</param>
	virtual void OnKeyRelease(UINT nChar, UINT nRepCnt, UINT nFlags);

	/// <summary>鼠标按下事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMousePress(UINT nFlags, CPoint point);

	/// <summary>鼠标释放事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMouseRelease(UINT nFlags, CPoint point);

	/// <summary>鼠标移动事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMouseMove(UINT nFlags, CPoint point);

	/// <summary>控件单击事件</summary>
	/// <param name="pContainer">被单击的容器</param>
	/// <param name="pControl">被单击的控件</param>
	/// <remarks>建议重载</remarks>
	virtual void OnClicked(CHnrjitContainer* pContainer, CHnrjitControl* pControl) {}

	/// <summary>处理命令消息</summary>
	/// <param name="wParam">详见MSDN</param>
	/// <param name="lParam">详见MSDN</param>
	/// <returns>详见MSDN</returns>
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);

	/// <summary>处理计时器消息</summary>
	/// <param name="nIDEvent">计时器ID</param>
	virtual void OnTimer(UINT_PTR nIDEvent);

	/// <summary>执行对话框初始化</summary>
	/// <returns>返回值忽略</returns>
	virtual BOOL OnInitDialog();

	/// <summary>窗口处理过程</summary>
	/// <param name="message">消息ID</param>
	/// <param name="wParam">参数1</param>
	/// <param name="lParam">参数2</param>
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);

public:
	/// <summary>弹出模态对话框</summary>
	/// <param name="hWndParent">父窗口</param>
	/// <returns>对话框返回值</returns>
	INT_PTR DoModal(HWND hWndParent = GetActiveWindow());

	/// <summary>结束模态对话框</summary>
	/// <param name="nRetCode">对话框返回值</param>
	/// <returns>是否结束成功</returns>
	BOOL EndDialog(int nRetCode);

	/// <summary>创建非模态对话框</summary>
	/// <param name="hWndParent">父窗口</param>
	/// <returns>是否创建成功</returns>
	BOOL Create(HWND hWndParent = NULL);

	/// <summary>销毁非模态对话框</summary>
	/// <returns>是否销毁成功</returns>
	BOOL DestroyWindow();

	static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

protected:
	/// <summary>添加容器</summary>
	/// <param name="pContainer">欲添加的容器</param>
	/// <returns>返回容器索引</returns>
	UINT AddContainer(CHnrjitContainer* pContainer);

	/// <summary>移除容器</summary>
	/// <param name="pContainer">欲移除的容器</param>
	/// <returns>是否移除成功</returns>
	BOOL RemoveContainer(CHnrjitContainer* pContainer);

	friend class CHnrjitContainer; // 允许容器类访问私有成员

public:

	# include "HnrjitDialog.Partial.h"

protected:
	CAtlString m_strCaption; // 对话框标题

	HWND m_hWnd; // 窗口句柄

	HWND m_hWndInsertAfter;// 插入次序（z-order）

	BOOL m_bModal; // 模态对话框

	HGLOBAL m_hTemplate; // 对话框模板

	CAtlArray<CHnrjitContainer*> m_arrContainers; // 容器数组

	CHnrjitContainer* m_pFocusCantainer; // 聚焦容器

private:
	PAINTSTRUCT m_PaintStruct;
};

#endif // HNRJITDIALOG_H